<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <el-form
          v-show="showSearch"
          ref="queryForm"
          :model="queryParams"
          :inline="true"
          label-width="100px"
        >
          <el-form-item label="账号名称" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入账号名称"
              clearable
              size="small"
              style="width: 200px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="是否处理" prop="status">
            <el-select
              v-model="queryParams.type"
              placeholder="反馈是否处理"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option :key="0" label="未处理" :value="0"/>
              <el-option :key="1" label="已处理" :value="1"/>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >搜索
            </el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">

          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              @click="handleDelete"
            >删除
            </el-button>
          </el-col>
          <el-table :data="problemList" style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"/>
            <el-table-column prop="userName" label="账号名称" align="center"/>
            <el-table-column  v-if="false" prop="id" label="id" align="center" hidden/>
            <el-table-column prop="type" label="反馈内容" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.type == '0'" type="success">bug反馈</el-tag>
                <el-tag v-if="scope.row.type == '1'" type="danger">优化建议</el-tag>
              </template>
            </el-table-column>

            <el-table-column prop="content" label="反馈内容" align="center"/>


            <el-table-column prop="flag" label="是否处理" align="center">
              <template slot-scope="scope">
                <el-switch
                  :value="scope.row.flag"
                  active-value="1"
                  inactive-value="0"
                  @change="handleStatusChange(scope.row)"
                />
              </template>
            </el-table-column>
            <el-table-column prop="handleTime" label="处理时间" align="center">
              <template slot-scope="scope">
                {{ scope.row.flag === '0' ? '' : scope.row.handleTime }}
              </template>
            </el-table-column>
            <el-table-column prop="createTime" label="反馈时间" align="center"/>
          </el-table>
        </el-row>
      </el-col>
    </el-row>
    <el-pagination
      :page-size.sync="queryParams.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :page-sizes="[10, 20, 30, 40]"
      :current-page.sync="queryParams.pageNum"
      @current-change="getList"
      @size-change="getList"
    />
  </div>
</template>

<script>
import {allProblemList, deleteProblem} from "@/api/feedback/feedback";

export default {
  data() {
    return {
      showSearch: true,
      queryParams:{
       pageNum: 1,
        pageSize: 10,
        userName: undefined,
        type: undefined
      },
      problemList:null,
      total:null
    }
  },
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal
        .confirm('是否删除当前选中数据项？')
        .then(function () {
          return deleteProblem(ids)
        })
        .then(() => {
          this.getList()
          this.$modal.msgSuccess('删除成功')
        })
        .catch(() => {
        })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    getList() {
      this.loading = true
      allProblemList(this.queryParams).then((response) => {
        this.problemList = response.list
      });
    },
    handleStatusChange(row) {
      const text = row.receiveFlag === '0' ? '领取' : '修改';
      this.$modal
        .confirm('确认将该条记录改为'+text+'状态')
        .then(function() {
          return changeExchangeStatus(row.id, row.receiveFlag === '0'?'1':'0').then((response) => {
            row.receiveFlag = row.receiveFlag === '0'?'1':'0'
          })
        })
        .then(() => {
          this.$modal.msgSuccess(text + '成功');
          this.getList();
        })
        .catch(function() {
          row.status = row.status === '0' ? '1' : '0'
        })
    },
  },
  created() {
    this.getList()
  },
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

